package tech.realcpf.duckengine1.app;

import tech.realcpf.duckengine1.biz.BizCatalog;
import tech.realcpf.duckengine1.biz.BizUserInstance;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StartUp {
    public static void main(String[] args) {
        MockUserInfo mockUserInfo = getMockUserInfo();
        BizUserInstance bizUserInstance = new BizUserInstance(mockUserInfo.getUserId(),mockUserInfo.getTenantId());
        bizUserInstance.init(mockUserInfo.getOssConfig());
        List<BizCatalog> catalogs = bizUserInstance.catalogs();
        /**
         * source table => tableName
         * source custom sql = > sql
         * target catalog => catalog
         * source jdbc uri => uri
         * source username => username
         * source password = > password
         */
        Map<String,Object> param = new HashMap();
        param.put("tableName","arrow.catalog_sales");
        param.put("catalog",catalogs.get(0));
        param.put("uri","jdbc:postgresql://localhost:5432/duck");
        param.put("username","realcpf");
        param.put("password","PostgreSQL");
        param.put("target","tbl_load_by_arrow");
        bizUserInstance.loadTableWithDataSource(param);
    }
    public static void main1(String[] args) {
        MockUserInfo mockUserInfo = getMockUserInfo();
        BizUserInstance bizUserInstance = new BizUserInstance(mockUserInfo.getUserId(),mockUserInfo.getTenantId());
        bizUserInstance.init(mockUserInfo.getOssConfig());
        bizUserInstance.catalogs().forEach(System.out::println);
        List<Map<String,Object>> data = bizUserInstance.queryWithBizSql("""
        select * from "default"."customer"
        order by c_customer_id
        limit 10
        """);
        data.forEach(System.out::println);
    }

    public static MockUserInfo getMockUserInfo() {
        return MockUserInfo.builder()
                .userId(1000L)
                .tenantId(1000L)
                .ossConfig("SET s3_url_style='path';\n" +
                        "SET s3_endpoint='127.0.0.1:9000';\n" +
                        "SET s3_access_key_id='admin' ;\n" +
                        "SET s3_secret_access_key='password';\n" +
                        "SET s3_use_ssl=false;\n" +
                        "SET VARIABLE biz_s3_bucket = \"duck\";\n" +
                        "SET VARIABLE biz_s3_base = \"demo1\";")
                .build();
    }
}
